package com.shop.front.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * Swagger API文档配置
 */
@Configuration
public class SwaggerConfig {

    @Value("${spring.profiles.active}")
    private String environment;

    @Bean
    public Docket createRestApi() {
        if("pro".equalsIgnoreCase(environment)) {
            return new Docket(DocumentationType.SWAGGER_2)
                    .select()
                    .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                    .paths(PathSelectors.none())
                    .build()
                    ;
        } else {
            return new Docket(DocumentationType.SWAGGER_2)
                    .select()
                    .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                    .paths(PathSelectors.any())
                    .build()
                    .apiInfo(apiInfo())
                    ;
        }
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Springboot版本GC-Tgl前后端分离演示平台 - 前台")
                .description("GC-Tgl使用GC-Framework基于Springboot搭建的前后端分离演示平台 - 前台")
                .termsOfServiceUrl("http://localhost:8080")
                .version("v1.0.0-SNAPSHOT")
                .build();
    }

}
